<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>郊狼惩罚姬 - 强度信息页面</title>
    <link rel="icon" type="image/ico" href="/DG-LAB.ico">
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #e8e8e8;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            height: 100vh;
        }

       .channel-progress {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-bottom: 20px;
        }

       .channel-progress-bar {
            width: 200px;
            height: 20px;
            background-color: #ddd;
            border-radius: 10px;
            overflow: hidden;
            position: relative;
        }

       .channel-progress-bar-fill {
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            border-radius: 10px;
            transition: width 0.5s ease;
        }

       .bg {
            position: relative;
            background-color: rgba(0, 0, 0, 0.6);
            border-radius: 10px;
            padding: 20px;
        }

       .channel-progress span {
            color: white;
        }
    </style>
    <script>
        function refreshPage() {
            fetch('/data')
              .then(response => response.json())
              .then(data => {
                    document.getElementById('a_channel').innerHTML = data.a_channel;
                    document.getElementById('a_channel_max').innerHTML = data.a_channel_max;
                    document.getElementById('b_channel').innerHTML = data.b_channel;
                    document.getElementById('b_channel_max').innerHTML = data.b_channel_max;
                    // 更新通道 A 的进度条
                    updateProgressBar('a_channel_progress', data.a_channel, data.a_channel_max);
                    // 更新通道 B 的进度条
                    updateProgressBar('b_channel_progress', data.b_channel, data.b_channel_max);
                    setTimeout(refreshPage, 500); // 每秒刷新一次
                });
        }

        function updateProgressBar(progressBarId, value, maxValue) {
            const progressBar = document.getElementById(progressBarId);
            const progressBarFill = progressBar.querySelector('.channel-progress-bar-fill');
            const percentage = (value / maxValue) * 100;
            progressBarFill.style.width = `${percentage}%`;

            // 根据百分比设置进度条颜色
            if (percentage >= 0 && percentage < 50) {
                progressBarFill.style.backgroundColor = 'green';
            } else if (percentage >= 50 && percentage < 90) {
                progressBarFill.style.backgroundColor = 'darkorange';
            } else if (percentage >= 90 && percentage <= 100) {
                progressBarFill.style.backgroundColor ='red';
            }
        }

        window.onload = refreshPage;
    </script>
</head>

<body>
    <div class="bg">
        <div class="channel-progress">
            <span>通道 A 强度：<span id="a_channel">0</span> 强度上限：<span id="a_channel_max">50</span></span>
            <br />
            <div class="channel-progress-bar" id="a_channel_progress">
                <div class="channel-progress-bar-fill"></div>
            </div>
        </div>
        <div class="channel-progress">
            <span>通道 B 强度：<span id="b_channel">0</span> 强度上限：<span id="b_channel_max">50</span></span>
            <br />
            <div class="channel-progress-bar" id="b_channel_progress">
                <div class="channel-progress-bar-fill"></div>
            </div>
        </div>
    </div>
</body>

</html>